<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Deque {
            constructor() {
                    this.item = [];
                }
                //前端插入
            addFront(element) {
                    this.item.unshift(element);
                }
                //后端插入
            addBack(element) {
                this.item.push(element);
            }
            removeFront() {
                return this.item.shift();
            }
            removeBack() {
                return this.item.pop();
            }
            toString() {
                return this.item.toString();
            }
            peekBack() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[this.item.length - 1];
                }
            }
        }
        const deque = new Deque();
        deque.addBack("john");
        deque.addBack("jack");
        deque.addFront("camila");
        console.log("打印所有" + deque.toString());
        console.log("前一" + deque.addFront());
        console.log("后一" + deque.addBack());
        console.log("移除前1" + deque.removeFront());
        console.log("移除后1" + deque.removeBack());
    </script>
</body>

</html>